﻿using Example.Command.Handler;
using Microsoft.Extensions.Hosting;
using SuperSocket.ProtoBase;
using SuperSocket.Command;
using SuperSocket.Server;
using SuperSocket.Server.Host;


var builder = SuperSocketHostBuilder.Create<StringPackageInfo, CommandLinePipelineFilter>();


/******************************* 全局会话 *******************************/

builder.UseSessionHandler((session) => {
        Console.WriteLine($"=> {session.RemoteEndPoint} 已连接");
        return session.SendAsync("[Server]已成功连接到服务器...\r\n\r\n"u8.ToArray());
    }, (session, reason) => {
        Console.WriteLine($"=> {session.RemoteEndPoint} 已断开,{reason}");
        return ValueTask.CompletedTask;
    });


/***************************** (路由)处理命令 ****************************/

builder.UseCommand(opt => {
    opt.AddCommand<Add>();
    opt.AddCommand<Sub>();
});

var host = builder.Build();
await host.RunAsync();